package com.exam.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.dao.AdminMapper;
import com.exam.domain.Student;
import com.exam.service.AdminService;
import com.exam.utils.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员页面")
@RestController
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @PostMapping("/login")
    @ApiOperation(value = "管理员登录", notes = "管理员登录")
    public ResultBody login(@RequestParam("id") String id,@RequestParam("password") String password) {
        return ResultBody.success(adminService.login(id,password));
    }

    @PostMapping("/studentCertify")
    @ApiOperation(value = "认证学生", notes = "认证学生")
    @SaCheckPermission("admin")
    public ResultBody studentCertify(@RequestParam String id, @RequestParam boolean certified) {
        return ResultBody.success(adminService.studentCertify(id, certified));
    }

    @PostMapping("/teacherCertify")
    @ApiOperation(value = "认证教师", notes = "认证教师")
    @SaCheckPermission("admin")
    public ResultBody teacherCertify(@RequestParam String id, @RequestParam boolean certified) {
        return ResultBody.success(adminService.teacherCertify(id, certified));
    }

    @GetMapping("/getQuestion")
    @ApiOperation(value = "管理员从网络获取题目", notes = "管理员从网络获取题目")
    public ResultBody getQuestion() {
        return ResultBody.success(adminService.getQuestion());
    }

    @GetMapping("/getQuestionList")
    @ApiOperation(value = "管理员获取题目列表", notes = "管理员获取题目列表")
    public ResultBody getQuestionList() {
        return ResultBody.success(adminService.getQuestionList());
    }


    /**
     * 获取全部学生名单（分页）
     * @param index 页码
     * @param pageSize 每页条目数
     * @return 全部学生名单（分页）
     */
    @GetMapping("/getAllStudent")
    @SaCheckPermission("admin")
    @ApiOperation(value = "获取全部学生", notes = "获取全部学生")
    public ResultBody getAllStudent(int index, int pageSize) {
        return ResultBody.success(adminService.getAllStudent(index, pageSize));
    }

    /**
     * 获取全部教师名单（分页）
     * @param index 页码
     * @param pageSize 每页条目数
     * @return 全部教师名单（分页）
     */
    @GetMapping("/getAllTeacher")
    @ApiOperation(value = "获取全部教师", notes = "获取全部教师")
    @SaCheckPermission("admin")
    public ResultBody getAllTeacher(int index, int pageSize) {
        return ResultBody.success(adminService.getAllTeacher(index, pageSize));
    }

    /**
     * 根据审核状态获取学生名单（分页）
     * @param index 页码
     * @param pageSize 每页条目数
     * @param certified 认证状态
     * @return 不同审核状态的学生名单（分页）
     */
    @GetMapping("/getAllStudentByCertified")
    @ApiOperation(value = "不同审核状态的学生名单", notes = "不同审核状态的学生名单")
    @SaCheckPermission("admin")
    public ResultBody getAllStudent(int index, int pageSize, String certified) {
        return ResultBody.success(adminService.getStudentByCertified(index, pageSize, certified));
    }

    /**
     * 根据审核状态获取教师名单（分页）
     * @param index 页码
     * @param pageSize 每页条目数
     * @param certified 认证状态
     * @return 不同审核状态的教师名单（分页）
     */
    @GetMapping("/getAllTeacherByCertified")
    @ApiOperation(value = "不同审核状态的教师名单", notes = "不同审核状态的教师名单")
    @SaCheckPermission("admin")
    public ResultBody getAllTeacher(int index, int pageSize, String certified) {
        return ResultBody.success(adminService.getTeacherByCertified(index, pageSize, certified));
    }
}
